import { Task } from '@/business/task/entities/task.entity';
import { User } from '@/business/user/entities/user.entity';
import { CommonEntity } from '@/common/common-entity';
import { ApiPropertyOptional } from '@nestjs/swagger';
import { Column, Entity, OneToMany } from 'typeorm';

@Entity()
export class Adventure extends CommonEntity {
  @ApiPropertyOptional({ description: '工会名称' })
  @Column({
    type: 'varchar',
    comment: '工会名称',
    unique: true,
    nullable: false
  })
  name: string;

  @ApiPropertyOptional({ description: '工会称号' })
  @Column({
    type: 'varchar',
    comment: '工会称号'
  })
  title: string;

  @ApiPropertyOptional({ description: '最大成员数量' })
  @Column({
    type: 'int',
    comment: '最大成员数量',
    default: 10
  })
  memberNum: number;

  @ApiPropertyOptional({ description: '等级' })
  @Column({
    type: 'int',
    comment: '等级',
    default: 1
  })
  level: number;

  @ApiPropertyOptional({ description: '工会描述' })
  @Column({
    type: 'varchar',
    comment: '工会描述',
    default: ''
  })
  desc: string;

  // 一个工会领取多个任务 一对多关系
  @OneToMany(() => Task, (task) => task.adventure)
  tasks: Task[];

  // 一个工会可以有多个user 一对多
  @OneToMany(() => User, (user) => user.adventure, {
    eager: true, // 查询Adventure时，加载关联的User
    cascade: ['insert', 'update']
  })
  members: User[];
}
